//
//  ChooseWithConditionNewViewController.m
//  CarUser
//
//  Created by 王森林 on 2019/1/25.
//  Copyright © 2019年 王森林. All rights reserved.
//

#import "ChooseWithConditionNewViewController.h"
#import "ChooseResultViewController.h"
@interface ChooseWithConditionNewViewController ()
@property  (nonatomic, strong) UILabel *selectLabel; //展示条件label


@property  (nonatomic, strong) NSMutableArray *bodyAry; //座数选择
@property  (nonatomic, strong) NSMutableArray *seatNumAry; //车身选择
@property  (nonatomic, strong) NSArray *priceAry; //价位选择
@property  (nonatomic, strong) NSArray *bodyAllAry; //座数选择
@property  (nonatomic, strong) NSArray *seatNumAllAry; //车身选择
@property  (nonatomic, strong) NSString *jb0000; //级别，如suv、mpv，（需从代码表读取）
@property  (nonatomic, strong) NSString *csjg00; //车身结构，如5门5座（需从代码表读取）
@property  (nonatomic, strong) NSString *zdjgmin; //最低终端价格
@property  (nonatomic, strong) NSString *zdjgmax; //最高终端价格

@property  (nonatomic, strong) UIButton *csPreBtn;
@property  (nonatomic, strong) UIButton *jbPreBtn;
@property  (nonatomic, strong) UIButton *pricePreBtn;
@property  (nonatomic, strong)  UIButton *resetBtn;

@end
#define JBTAG 1000
#define JBIMAGE 1000000
#define JBTITLE 100000000
#define CSTAG 10000
#define PRICETAG 100000
@implementation ChooseWithConditionNewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTopView];
    [self createFootView];
    self.mainTableView.frame = CGRectMake(0, 45, BOUNDWIDTH, BOUNDHEIGHT -NAV_HEIGHT -TABBAR_HEIGHT  -  45 );
    
    self.jb0000 = @"";
    self.csjg00 = @"";
    self.zdjgmax = @"";
    self.zdjgmin = @"";
    
    
    
//    [self createUI];
    [self fetchDataFromNet];
    
    self.mainTableView.mj_header = [Custom_Mjfresh mj_customMjfreshHeaderSetting:^{
        [self fetchDataFromNet];
    }];
    // Do any additional setup after loading the view.
}


- (void)fetchDataFromNet
{
    //座数
    NSDictionary *params = @{
                             @"FKEY":[CommonMethod createMD5Key:@"DICTIONARIES_ID"],
                             @"DICTIONARIES_ID":@"7408ec459ab74b958a8670cdf0a0e7a1"
                             
                             };
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:nil];
    });
    
    [[ZY_AfnNetManager shareInstance]postWithURL:Car_API_7 params:params md5Paraname:nil success:^(id  _Nullable response) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
        
             [self.mainTableView.mj_header endRefreshing];
        NSDictionary *resultDict  = response;
        NSArray *ary = [resultDict objectForKey:@"list"];
        if (ary != nil && ![ary isKindOfClass:[NSNull class]] && ary.count != 0)
        {
            self.bodyAllAry = [NSArray arrayWithArray:[resultDict objectForKey:@"list"]];
            self.bodyAry = [[NSMutableArray alloc] init];

            [self.bodyAllAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [self.bodyAry addObject:[obj objectForKey:@"name"]];
            }];
//            NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:1]; // 组数
//            [self.mainTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];

        }
        if (self.seatNumAry.count  > 0 && self.bodyAry.count > 0) {
            self.priceAry = @[@"20-30万",@"30-50万",@"50-80万",@"80万以上"];
            [self.mainTableView  reloadData];
        }
        
        
    } fail:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
                 [self.mainTableView.mj_header endRefreshing];
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        });
        
    }];
    
    
    //车身
    NSDictionary *params1 = @{
                              @"FKEY":[CommonMethod createMD5Key:@"DICTIONARIES_ID"],
                              @"DICTIONARIES_ID":@"ba32f6fea4274c099175fa7a857cfd04"
                              
                              };
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD showWithStatus:nil];
    });
    
    [[ZY_AfnNetManager shareInstance]postWithURL:Car_API_7 params:params1 md5Paraname:nil success:^(id  _Nullable response) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
        });
             [self.mainTableView.mj_header endRefreshing];
        NSDictionary *resultDict  = response;
        NSArray *ary = [resultDict objectForKey:@"list"];
        if (ary != nil && ![ary isKindOfClass:[NSNull class]] && ary.count != 0)
        {
            self.seatNumAllAry = [NSArray arrayWithArray:[resultDict objectForKey:@"list"]];
            self.seatNumAry = [[NSMutableArray alloc] init];
           
            [self.seatNumAllAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [self.seatNumAry addObject:[obj objectForKey:@"name"]];
            }];
//            NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:0]; // 组数
//            [self.mainTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
            
        }
        
        if (self.seatNumAry.count  > 0 && self.bodyAry.count > 0) {
            self.priceAry = @[@"20-30万",@"30-50万",@"50-80万",@"80万以上"];
            [self.mainTableView  reloadData];
        }
        
    } fail:^(NSError * _Nonnull error) {
        dispatch_async(dispatch_get_main_queue(), ^{
                 [self.mainTableView.mj_header endRefreshing];
            [SVProgressHUD showErrorWithStatus:error.localizedDescription];
        });
        
    }];
    
    
}

- (void)createTopView
{
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, BOUNDWIDTH, 45)];
    [self.view addSubview:topView];
    
    [topView addSubview:self.selectLabel];
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 44.5, BOUNDWIDTH, 0.5)];
    lineLabel.backgroundColor = Common_SepeColor;
    [topView addSubview:lineLabel];
    
    
}


- (void)handleResetAction:(id)sender
{
     self.csPreBtn.selected = NO;
     self.csPreBtn.layer.borderColor = Common_Head_Color.CGColor;
     self.csPreBtn.layer.borderWidth = 1;
   
    self.pricePreBtn.selected = NO;
    self.pricePreBtn.layer.borderColor = Common_Head_Color.CGColor;
    self.pricePreBtn.layer.borderWidth = 1;
    self.jbPreBtn.selected = NO;
    NSInteger pretag = self.jbPreBtn.tag - JBTAG;
    UIImageView *imageView = [self.jbPreBtn viewWithTag:JBIMAGE + pretag];
    UILabel *titleLabel = [self.jbPreBtn viewWithTag:JBTITLE+pretag];
    titleLabel.textColor =  Common_TextColor;
    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"contion%ld",pretag+1]];
    
    self.pricePreBtn = nil;
    self.jbPreBtn  = nil;
    self.csPreBtn = nil;
    [self updateTitleShow];
    self.jb0000 = @"";
    self.csjg00 = @"";
    self.zdjgmax = @"";
    self.zdjgmin = @"";
    [ self.resetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [ self.resetBtn setBackgroundColor:[UIColor grayColor]];
    
}



//搜索
- (void)handleSearchAction:(id)sender
{
    
    ChooseResultViewController  *controller  = [[ChooseResultViewController alloc] init];
    controller.pushType = 2;
    controller.jb0000 = self.jb0000;
    controller.csjg00 = self.csjg00;
    controller.zdjgmax = self.zdjgmax;
    controller.zdjgmin = self.zdjgmin;
    
    if (self.jbPreBtn) {
        controller.jb0000Index = self.jbPreBtn.tag - JBTAG;
    } else {
        controller.jb0000Index = -1;
        
    }
    
    if (self.csPreBtn) {
        controller.csjg00Index = self.csPreBtn.tag - CSTAG;
        
    } else {
        controller.csjg00Index = -1;
        
    }
    if (self.pricePreBtn) {
       
         controller.priceIndex = self.pricePreBtn.tag - PRICETAG;
    } else {
        controller.priceIndex = -1;
    }
    
    [self.navigationController pushViewController:controller animated:YES];
    
}


- (void)createFootView
{
  
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, BOUNDHEIGHT - 65-NAV_HEIGHT-TABBAR_HEIGHT, BOUNDWIDTH, 65)];
    [self.view addSubview:footView];
  
    self.resetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [ self.resetBtn setTitle:@"重置" forState:UIControlStateNormal];
  
     self.resetBtn.titleLabel.font = FONT_SIZE(14);
    [ self.resetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [ self.resetBtn setBackgroundColor:[UIColor grayColor]];
     self.resetBtn.layer.cornerRadius = 20;
     self.resetBtn.layer.masksToBounds = YES;
    [ self.resetBtn addTarget:self action:@selector(handleResetAction:) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview: self.resetBtn];
    [ self.resetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(footView.mas_left).offset(15);
        make.top.mas_equalTo(footView.mas_top);
        make.height.mas_equalTo(44);
        make.width.mas_equalTo(90);
    }];
    
    UIButton *selectNumBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [selectNumBtn setTitle:@"筛选" forState:UIControlStateNormal];
    [selectNumBtn setTitleColor:RGB(255, 218, 68) forState:UIControlStateNormal];
    selectNumBtn.titleLabel.font = FONT_SIZE(14);
    [selectNumBtn setBackgroundColor:RGB(50, 50, 50)];
    selectNumBtn.layer.cornerRadius = 20;
    selectNumBtn.layer.masksToBounds = YES;
    [selectNumBtn addTarget:self action:@selector(handleSearchAction:) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:selectNumBtn];
    [selectNumBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo( self.resetBtn.mas_right).offset(15);
        make.right.mas_equalTo(footView.mas_right).offset(-15);
        make.top.mas_equalTo(footView.mas_top);
        make.height.mas_equalTo(44);
        
    }];
    
}

- (void)updateTitleShow
{
    NSMutableString *str = [[NSMutableString alloc] init];
    if (self.jbPreBtn) {
        NSInteger pretag = self.jbPreBtn.tag - JBTAG;
        UILabel *titleLabel = [self.jbPreBtn  viewWithTag:JBTITLE+pretag];
        [str appendString:[NSString stringWithFormat:@"%@",titleLabel.text]];
    }
    
    if (self.csPreBtn) {
        if (![CommonMethod isBlankString:str]) {
             [str appendString:[NSString stringWithFormat:@"/%@",self.csPreBtn.titleLabel.text]];
        } else {
            [str appendString:[NSString stringWithFormat:@"%@",self.csPreBtn.titleLabel.text]];
            
        }
       
    }
    if (self.pricePreBtn) {
        if (![CommonMethod isBlankString:str]) {
               [str appendString:[NSString stringWithFormat:@"/%@",self.pricePreBtn.titleLabel.text]];
         } else {
               [str appendString:[NSString stringWithFormat:@"%@",self.pricePreBtn.titleLabel.text]];
             
         }
      
    }
    if (![CommonMethod isBlankString:str]) {
        [ self.resetBtn setTitleColor:RGB(50, 50, 50) forState:UIControlStateNormal];
        [ self.resetBtn setBackgroundColor:RGB(255, 218, 68)];
        self.selectLabel.text = str;
    } else {
        self.selectLabel.text =  @"您选择的条件会显示在这儿";
        [ self.resetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [ self.resetBtn setBackgroundColor:[UIColor grayColor]];
    }
 
 
}


- (void)handleSelectJBAction:(id)sender
{
    UIButton *btn = sender;
    NSInteger tag = btn.tag - JBTAG;
    if (!btn.selected) {
        btn.selected = YES;
        UIImageView *imageView = [btn viewWithTag:JBIMAGE + tag];
        UILabel *titleLabel = [btn viewWithTag:JBTITLE+tag];
        titleLabel.textColor = RGB(228, 74, 65);
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"contion%ld_select",tag+1]];

        //处理选中
        __block NSDictionary *dict = nil;
        [self.seatNumAllAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([[obj objectForKey:@"name"] isEqualToString:titleLabel.text]) {
                dict = obj;
            }
        }];
        self.jb0000 = [dict objectForKey:@"bianma"];
     
        
    } else {
        btn.selected = NO;
        UIImageView *imageView = [btn viewWithTag:JBIMAGE + tag];
        UILabel *titleLabel = [btn viewWithTag:JBTITLE+tag];
        titleLabel.textColor =  Common_TextColor;
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"contion%ld",tag+1]];
        
        self.jb0000 = @"";
        
    }
    
    if (self.jbPreBtn) {
        if (self.jbPreBtn == btn) {
//            self.jbPreBtn = nil;
        } else  {
            self.jbPreBtn.selected = NO;
             NSInteger pretag = self.jbPreBtn.tag - JBTAG;
            UIImageView *imageView = [self.jbPreBtn viewWithTag:JBIMAGE + pretag];
            UILabel *titleLabel = [self.jbPreBtn viewWithTag:JBTITLE+pretag];
            titleLabel.textColor =  Common_TextColor;
            imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"contion%ld",pretag+1]];
//            self.jb0000 = @"";
           
        }
        
        
    }
    if (self.jbPreBtn == btn) {
         self.jbPreBtn = nil;
         self.jb0000 = @"";
    } else {
        self.jbPreBtn = btn;
        
    }
   
    [self updateTitleShow];
    
}

- (void)handleSelectCSAction:(id)sender
{
    
    UIButton *btn = sender;
    if (!btn.selected) {
        btn.selected = YES;
        btn.layer.borderColor =  RGB(228, 74, 65).CGColor;
        btn.layer.borderWidth = 1;
        
        
        //处理选中
        __block NSDictionary *dict = nil;
        [self.bodyAllAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([[obj objectForKey:@"name"] isEqualToString:btn.titleLabel.text]) {
                dict = obj;
            }
        }];
        self.csjg00 = [dict objectForKey:@"bianma"];
        
    } else {
        btn.layer.borderColor = Common_Head_Color.CGColor;
        btn.layer.borderWidth = 1;
        btn.selected = NO;
          self.csjg00 = @"";
     
    }
    
    if (self.csPreBtn) {
        if (self.csPreBtn == btn) {
        } else  {
            self.csPreBtn.selected = NO;
            self.csPreBtn.layer.borderColor = Common_Head_Color.CGColor;
            self.csPreBtn.layer.borderWidth = 1;
//              self.csjg00 = @"";
         
        }
        
        
    }
    if (self.csPreBtn == btn) {
        self.csPreBtn = nil;
        self.csjg00 = @"";
    } else {
        self.csPreBtn = btn;
    }
    [self updateTitleShow];
}

//价格
- (void)handleSelectPriceAction:(id)sender
{
    
    UIButton *btn = sender;
    NSInteger tag  = btn.tag - PRICETAG;
    if (!btn.selected) {
        btn.selected = YES;
        btn.layer.borderColor =  RGB(228, 74, 65).CGColor;
        btn.layer.borderWidth = 1;
        
        switch (tag) {
            case 0:
            {
                self.zdjgmax = @"30";
                self.zdjgmin = @"20";
                
            }
                break;
            case 1:
            {
                self.zdjgmax = @"50";
                self.zdjgmin = @"30";
                
            }
                break;
            case 2:
            {
                self.zdjgmax = @"80";
                self.zdjgmin = @"50";
                
            }
                break;
            case 3:
            {
                self.zdjgmax = @"10000";
                self.zdjgmin = @"80";
                
            }
                break;
                
            default:
                break;
        }
        
    } else {
        btn.selected = NO;
        btn.layer.borderColor = Common_Head_Color.CGColor;
        btn.layer.borderWidth = 1;
        self.zdjgmax = @"";
        self.zdjgmin = @"";
    }
    
    if (self.pricePreBtn) {
        if (self.pricePreBtn == btn) {
//            self.zdjgmax = @"";
//            self.zdjgmin = @"";
        } else  {
            self.pricePreBtn.selected = NO;
            self.pricePreBtn.layer.borderColor = Common_Head_Color.CGColor;
            self.pricePreBtn.layer.borderWidth = 1;
          
        }
        
        
    }

    
    if (self.pricePreBtn == btn) {
        self.pricePreBtn = nil;
        self.zdjgmax = @"";
        self.zdjgmin = @"";
    } else {
        self.pricePreBtn = btn;
    }
    [self updateTitleShow];
}


#pragma mark - 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}
#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 0;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    switch (section) {
        case 0:
        {
            if (self.seatNumAry.count == 0) {
                return  0;
            } else {
                if (self.seatNumAry.count % 3 == 0) {
                    return 40+80*(self.seatNumAry.count/3);
                } else {
                    
                    return 40+80*(self.seatNumAry.count/3+1);
                }
                
                
            }
        
            
        }
            break;
        case 1:
        {
         
            if (self.bodyAry.count == 0) {
                return 0;
            } else {
                if (self.bodyAry.count %4 == 0) {
                    return 50+50*(self.bodyAry.count/4);
                } else {
                    
                    return 50+50*(self.bodyAry.count/4+1);
                }
                
            }
        
            
            
        }
            break;
        case 2:
        {
            if (self.priceAry.count == 0) {
                return 0;
            } else {
                if (self.priceAry.count %3 == 0) {
                    return 50+50*(self.priceAry.count/3);
                } else {
                    
                    return 50+50*(self.priceAry.count/3+1);
                }
                
                
            }
        
            
        }
            break;
            
        default:
            return 0;
            break;
    };
}



- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    UIView *headView = [UIView new];
    
    UILabel *lineLabel = [UILabel new];
    lineLabel.frame = CGRectMake(15, 15, 5, 15);
    lineLabel.backgroundColor = Common_TextLowColor;
    lineLabel.layer.cornerRadius = 3;
    lineLabel.layer.masksToBounds = YES;
    [headView addSubview:lineLabel];
    
    UILabel  *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 15, 1000, 15)];
    titleLabel.text = @"车身";
    titleLabel.font = B_FONT_SIZE(16);
    titleLabel.textColor = [UIColor blackColor];
    [headView addSubview:titleLabel];
 
    
 
    switch (section) {
        case 0:
        {
            
            float btnWidth = (BOUNDWIDTH - 50)/3;
            float btnHeight = 80;
            titleLabel.text = @"车身";
            [self.seatNumAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                btn.frame = CGRectMake(15+idx%3*(btnWidth+10), 40+ 80*(idx/3), btnWidth, btnHeight);
                UIImage *image = nil;
                if ([obj isEqualToString:@"SUV"]) {
                    image = IMG(@"contion1");
                    //                    [btn setImage:IMG(@"contion1") forState:UIControlStateNormal];
                    //                    [btn setImage:IMG(@"contion1_select") forState:UIControlStateSelected];
                }
                if ([obj isEqualToString:@"轿车"]) {
                    image = IMG(@"contion2");
                    //                    [btn setImage:IMG(@"contion2") forState:UIControlStateNormal];
                    //                    [btn setImage:IMG(@"contion2_select") forState:UIControlStateSelected];
                }
                if ([obj isEqualToString:@"MVP"]) {
                    image = IMG(@"contion3");
                    //                    [btn setImage:IMG(@"contion3") forState:UIControlStateNormal];
                    //                    [btn setImage:IMG(@"contion3_select") forState:UIControlStateSelected];
                                }
                    if ([obj isEqualToString:@"跑车"]) {
                        image = IMG(@"contion4");
                        //                    [btn setImage:IMG(@"contion4") forState:UIControlStateNormal];
                        //                    [btn setImage:IMG(@"contion4_select") forState:UIControlStateSelected];
                    }
                    if ([obj isEqualToString:@"皮卡"]) {
                        image = IMG(@"contion5");
                        //                    [btn setImage:IMG(@"contion5") forState:UIControlStateNormal];
                        //                    [btn setImage:IMG(@"contion5_select") forState:UIControlStateSelected];
                    }
                    if ([obj isEqualToString:@"房车"]) {
                        image = IMG(@"contion6");
                        //                    [btn setImage:IMG(@"contion6") forState:UIControlStateNormal];
                        //                    [btn setImage:IMG(@"contion6_select") forState:UIControlStateSelected];
                    }
                
                    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((btnWidth - 72)/2, 10, 72, 42)];
                    imageView.image = image;
                     imageView.contentMode = UIViewContentModeScaleAspectFit;
                    imageView.tag = JBIMAGE + idx;
                    [btn addSubview:imageView];
                    
                    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, btnHeight - 25, btnWidth, 15)];
                    titleLabel.text = obj;
                    titleLabel.font = FONT_SIZE(14);
                    titleLabel.textAlignment = NSTextAlignmentCenter;
                    titleLabel.textColor = Common_TextColor;
                    titleLabel.tag = JBTITLE + idx;
                    [btn addSubview:titleLabel];

                    btn.tag = JBTAG+idx;
                    [btn addTarget:self action:@selector(handleSelectJBAction:) forControlEvents:UIControlEventTouchUpInside];

//                if (!self.jbPreBtn && idx == 0) {
//
//                    btn.selected = YES;
//                    self.jbPreBtn = btn;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//
//                }
//                if (self.jbPreBtn.tag == btn.tag) {
//                    btn.selected = YES;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//                    self.jbPreBtn = btn;
//                }
                [headView addSubview:btn];
                }];
            
        }
            break;
        case 1:
        {
            float btnWidth = (BOUNDWIDTH - 50)/4-10;
            float marX = (BOUNDWIDTH - 30 - btnWidth*4)/3;
            float btnHeight = 35;
            titleLabel.text = @"座数";
            [self.bodyAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                btn.frame = CGRectMake(15+idx%4*(btnWidth+marX), 50+ 50*(idx/4), btnWidth, btnHeight);
                [btn setTitle: obj forState:UIControlStateNormal];
                [btn setTitleColor:Common_TextColor forState:UIControlStateNormal];
                [btn setTitleColor: RGB(228, 74, 65) forState:UIControlStateSelected];
                btn.titleLabel.font = FONT_SIZE(14);
                btn.layer.cornerRadius = 5;
                btn.layer.masksToBounds = YES;
                btn.layer.borderColor = Common_Head_Color.CGColor;
                btn.layer.borderWidth = 1;
//                [btn setBackgroundColor:Common_BackgroundGrayColor];
                btn.tag = CSTAG+idx;
                [btn addTarget:self action:@selector(handleSelectCSAction:) forControlEvents:UIControlEventTouchUpInside];
//                if (!self.csPreBtn && idx == 0) {
//
//                    btn.selected = YES;
//                    self.csPreBtn = btn;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//
//                }
//                if (self.csPreBtn.tag == btn.tag) {
//                    btn.selected = YES;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//                    self.csPreBtn = btn;
//                }
                [headView addSubview:btn];
            }];

        }
            break;
        case 2:
        {
            float btnWidth = (BOUNDWIDTH - 50)/3-10;
            float marX = (BOUNDWIDTH - 30 - btnWidth*3)/3;
            float btnHeight = 35;
            titleLabel.text = @"价格";
            [self.priceAry enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                btn.frame = CGRectMake(15+idx%3*(btnWidth+marX), 50+ 50*(idx/3), btnWidth, btnHeight);
                [btn setTitle: obj forState:UIControlStateNormal];
                [btn setTitleColor:Common_TextColor forState:UIControlStateNormal];
                [btn setTitleColor: RGB(228, 74, 65) forState:UIControlStateSelected];
                btn.titleLabel.font = FONT_SIZE(14);
                btn.layer.cornerRadius = 5;
                btn.layer.masksToBounds = YES;
//                [btn setBackgroundColor:Common_BackgroundGrayColor];
                btn.layer.borderColor = Common_Head_Color.CGColor;
                btn.layer.borderWidth = 1;
                btn.tag = PRICETAG+idx;
                [btn addTarget:self action:@selector(handleSelectPriceAction:) forControlEvents:UIControlEventTouchUpInside];
//                if (!self.pricePreBtn && idx == 0) {
//                    
//                    btn.selected = YES;
//                    self.pricePreBtn = btn;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//                    
//                }
//                if (self.pricePreBtn.tag == btn.tag) {
//                    btn.selected = YES;
//                    btn.layer.borderColor = [UIColor redColor].CGColor;
//                    btn.layer.borderWidth = 1;
//                    self.pricePreBtn = btn;
//                }
                [headView addSubview:btn];
            }];

        }
            break;
            
        default:
            break;
    }
    
    return headView;
}


//- (NSArray *)priceAry
//{
//    if (!_priceAry) {
//        _priceAry = @[@"20-30万",@"30-50万",@"50-80万",@"80万以上"];
//    }
//    return _priceAry;
//}


- (UILabel *)selectLabel
{
    if (!_selectLabel) {
        _selectLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, BOUNDWIDTH-15*2, 45.0f)];
        _selectLabel.font = FONT_SIZE(14);
        _selectLabel.textColor = Common_HeadTitle_Color;
        _selectLabel.text = @"您选择的条件会显示在这儿";
        
    }
    return _selectLabel;
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
